package com.bytedance.retrofit2.mime;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class MimeUtil {
    private static final Pattern CHARSET = Pattern.compile("\\Wcharset=([^\\s;]+)", 2);

    public static String parseCharset(String mimeType, String defaultCharset) {
        Matcher matcher = MimeUtil.CHARSET.matcher(mimeType);
        if (matcher.find()) {
            defaultCharset = matcher.group(1).replaceAll("[\"\\\\]", "");
        }
        return defaultCharset;
    }
}

